package com.ph.irp.base.assistantmaterial.action;
import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.ph.irp.base.assistantmaterial.service.PBaseAssistantmaterialCandiatecategoryService;
import com.ph.irp.model.PBaseAssistantmaterialCandiatecategory;

public class AssistantmaterialCandiatecategoryAction extends ActionSupport {	
	private PBaseAssistantmaterialCandiatecategoryService candiateCategoryService;
	
	private List<PBaseAssistantmaterialCandiatecategory> candiateCategorys;
	private PBaseAssistantmaterialCandiatecategory candiateCategory;//公共属性确保在每一个方法中使用后又能被置空

	private Object[] rowlist = null;
    private String answer=null;
	
	public String getAnswer() {
		return answer;
	}

	public void setAnswer(String answer) {
		this.answer = answer;
	}


	public PBaseAssistantmaterialCandiatecategoryService getCandiateCategoryService() {
		return candiateCategoryService;
	}

	public void setCandiateCategoryService(
			PBaseAssistantmaterialCandiatecategoryService candiateCategoryService) {
		this.candiateCategoryService = candiateCategoryService;
	}

	public List<PBaseAssistantmaterialCandiatecategory> getCandiateCategorys() {
		return candiateCategorys;
	}

	public void setCandiateCategorys(
			List<PBaseAssistantmaterialCandiatecategory> candiateCategorys) {
		this.candiateCategorys = candiateCategorys;
	}

	public PBaseAssistantmaterialCandiatecategory getCandiateCategory() {
		return candiateCategory;
	}

	public void setCandiateCategory(
			PBaseAssistantmaterialCandiatecategory candiateCategory) {
		this.candiateCategory = candiateCategory;
	}

	public Object[] getRowlist() {
		return rowlist;
	}

	public void setRowlist(Object[] rowlist) {
		this.rowlist = rowlist;
	}

	public String showCandiatecategoryList() throws Throwable {
		candiateCategorys = candiateCategoryService.getCandiateCategoryList();
		return "success";
	}

	public String searchCandiateCategory() throws Throwable {
		if(candiateCategory==null){
			candiateCategorys = candiateCategoryService.getCandiateCategoryList();
		}else{
		   if(!candiateCategory.getCandiateCategoryCode().equals("")&&!candiateCategory.getCandiateCategoryName().equals("")){
			   candiateCategorys = candiateCategoryService.getCandiateCategoryByNameAndCode(candiateCategory.getCandiateCategoryName(), candiateCategory.getCandiateCategoryCode());
		   }
		   else if(!candiateCategory.getCandiateCategoryCode().equals("")){
			   candiateCategorys= candiateCategoryService.getCandiateCategoryByCode(candiateCategory.getCandiateCategoryCode());
		   }else if(!candiateCategory.getCandiateCategoryName().equals("")){
			   candiateCategorys= candiateCategoryService.getCandiateCategoryByName(candiateCategory.getCandiateCategoryName());
		   }
		   else{
				candiateCategorys = candiateCategoryService.getCandiateCategoryList();
		   }
		}
		candiateCategory = null;
		answer="";
		return "success";
	}
	
	//List页面跳转到add新增页面
	public String addInputCandiateCategory(){
		candiateCategory=null;
		return "success";
	}
	//List页面跳转到update修改页面
	public String updateInputCandiateCategory() throws Throwable {
		Integer candiateCategoryId = Integer.valueOf((String) rowlist[0]);
		candiateCategory = candiateCategoryService.getCandiateCategoryById(candiateCategoryId);
		return "success";
	}
	
	public String addCandiateCategory() throws Throwable{
			candiateCategoryService.addCandiateCategory(candiateCategory);
			candiateCategory = null;
			answer="插入成功!";
			return "success";
	}

	public String updateCandiateCategory() throws Throwable{
			candiateCategoryService.updateCandiateCategory(candiateCategory);
			candiateCategory = null;
			answer="更新成功!";
			return "success";
	}

	public String deleteCandiateCategory() throws Throwable{
		for (int i = 0; i < rowlist.length; i++) {
			candiateCategoryService.deleteCandiateCategory(Integer.valueOf((String) rowlist[i]));
		}
		answer="删除成功！";
		return "success";
	}

	public String selectCandiateCategory() throws Throwable{
		if(candiateCategory==null){
			candiateCategorys = candiateCategoryService.getCandiateCategoryList();
		}else{
		   if(!candiateCategory.getCandiateCategoryCode().equals("")&&!candiateCategory.getCandiateCategoryName().equals("")){
			   candiateCategorys = candiateCategoryService.getCandiateCategoryByNameAndCode(candiateCategory.getCandiateCategoryName(), candiateCategory.getCandiateCategoryCode());
		   }
		   else if(!candiateCategory.getCandiateCategoryCode().equals("")){
			   candiateCategorys= candiateCategoryService.getCandiateCategoryByCode(candiateCategory.getCandiateCategoryCode());
		   }else{
			   candiateCategorys= candiateCategoryService.getCandiateCategoryByName(candiateCategory.getCandiateCategoryName());
		   }
		}
		return "success";
	}

}
